<?php
/**
 * FastApp.
 * 9/21/24
 * @Author deepsea159
 * @Contact telegram:deepsea159
 */

namespace App\Game\Api\Controller;

namespace App\Game\Api\Controller;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Aspect\ApiAuth;
use App\Game\Api\Service\TeamService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('api/game/team'), ApiAuth]
class TeamController extends ApiController
{
    #[Inject]
    public TeamService $service;

    #[GetMapping('level1')]
    public function level1(): ResponseInterface
    {
        return $this->success($this->service->level1());
    }


    #[GetMapping('level2')]
    public function level2(): ResponseInterface
    {
        return $this->success($this->service->level2());
    }

    #[GetMapping('statistics')]
    public function statistics(): ResponseInterface
    {
        $this->validate(['start_at' => 'date', 'end_at' => 'date|required_with:start_at']);
        return $this->success($this->service->statistics($this->request->all()));
    }

    #[GetMapping('bet')]
    public function bet(): ResponseInterface
    {
        $this->validate(['user_id' => 'integer', 'start_at' => 'date', 'end_at' => 'date|required_with:start_at']);
        return $this->success($this->service->bet($this->request->all()));
    }

    #[PostMapping('register')]
    public function register(): ResponseInterface
    {
        return $this->success($this->service->register($this->validate([
            'username' => 'required|min:6|max:32',
            'password' => 'required|min:6|max:32|confirmed',
            'password_confirmation' => 'required',
            'invite_code' => 'string',
        ], ['username.*' => fastapp_t('account.invalid_username')])));
    }
}